// var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
// var qqmapsdk;
const db = wx.cloud.database({
  env: 'cloud1-2g6vpgs796710242'
})

Page({
  data: {
    key: 'LQUBZ-OZFW3-6XC3I-3UTKW-3KNKV-3RFND',
    the_location: [],
    coverimg:"true",
    markers:[
      // {
      //   id: 18,
      //   title: "holder",
      //   longitude: 113.943289,
      //   latitude: 22.549041,
      //   iconPath:"https://636c-cloud1-2g6vpgs796710242-1304238103.tcb.qcloud.la/L1-logo-test1.png?sign=1f890b4fe37787de763d5c9d4249d973&t=1679501882", 
      //   width: 60,
      //   height: 60,
      //   borderRadius:'200',
      //   callout:{
      //     content: "新文科协会",
      //     padding:10,
      //     display:'ALWAYS',
      //     textAlign:'center',
      //     borderRadius:'200',
      //     bgColor:'#000000',
      //     color:'#FFFFFF',
      //     fontSize:'12',
      //   }
      // },
    ],
    show: false,
    duration: 300,
    position: 'right',
    round: true,
    overlay: true,
    customStyle: '',
    overlayStyle: '',
    aimCP:""
  },

  // library(e){
  //   var markid = e.detail.markerId
  //   var that = this
  //   if (e.detail.markerId == 18){
  //     wx.navigateTo({
  //       url: '/pages/audiotion1/audiotion1'
  //     })
  //   }
  // },

  onLoad: function (e) {
    // qqmapsdk = new QQMapWX({
    //   key: 'LQUBZ-OZFW3-6XC3I-3UTKW-3KNKV-3RFND'
    // });
    // this.get_addresscode()
    db.collection("House")
    .get()
    .then(res=>{
      console.log("L1信息",res)
      this.setData({
        markers:res.data
      })
    })
    .catch(err=>{
      console.log(err)
    })
  },

  get_addresscode() {
    var _self = this
    console.log("markers",this.data.markers)
    wx.request({
      url: 'https://restapi.amap.com/v3/geocode/geo?parameters',
      header: { 
        'Content-Type': 'application/json'
    },
      data: {
        key: "cddee357dd2e2bb7bf9df9bc69652238",
        address: "广东省广深圳市南山区科苑路科兴科学园腾讯音乐娱乐集团", 
      },
      success: function (res) {
        console.log("data",res.data)
        console.log("current_position of M",res.data.geocodes[0].location)
        var the_location = res.data.geocodes[0].location.split(',')
        _self.setData({
          the_location: res.data.geocodes[0].location.split(','),
        })
        console.log(the_location[0])
      },
      fail: function (err) {
        console.log ('获取地理位置失败',err)
      }
    })
  },

  cancelcimg() {
    this.setData({
      coverimg:false
    })
  },

  //拉起弹窗
  pop_cabinet(e) {
    console.log("拉起仓储",e)
    var cpid = e.markerId
    this.setData({
      aimCP:cpid
    })
    const position = "bottom"
    let customStyle = ''
    let duration = this.data.duration
    switch (position) {
      case 'top':
      case 'bottom':
        customStyle = 'height: 23%;'
        break
      case 'right':
        break
    }
    this.setData({
      position,
      show: true,
      customStyle,
      duration
    })
  },

  apply() {
    wx.showToast({
      title: '当前您的账号等级未到L2，暂无申请权限',
      icon: 'none',
      duration: 4000
    });
  },

  onShow: function () {
    // 调用接口
    // qqmapsdk.search({
    //   keyword: '墨渊',
    //   success: function (res) {
    //       console.log(res);
    //   },
    //   fail: function (res) {
    //       console.log(res);
    //   },
    //   complete: function (res) {
    //     console.log(res);
    //   }
    // });
  },

  onGuideTap(event) {
    var lname = event.currentTarget.dataset.lname
    wx.getFuzzyLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
      success: function (res) {
        console.log(res);
        var lati = res.latitude
        var long = res.longitude
        wx.openLocation({
          type: 'gcj02',
          latitude: lati,
          longitude: long,
          name: lname,
          scale: 28
        })
      }
    })
  },
})